// pages/product informationg/product information.js
Page({
    data:{
        proId:'',
        infor:{
            intro:'黑色/复古蓝/浅蓝色 三色可选',
            picture1:"",
            picture2:"",
            text_1:'高腰拉长腰线 显高显瘦',
            picture3:"",
            categoryId:''
        },
        
    },
    queryPicture(){
        var that = this;
        wx.request({
            url: 'http://localhost:8080/product/searchById?proId='+that.data.proId,
            method:'POST',
            header:{
                'content-type':'application/json'
            },
            success:function(res) {
                console.log(res);
                that.setData({
                    infor:res.data.data,
                });
                console.log(that.data.infor);
            },
        })
    },
    jumpCart(){
        var that = this;
        var  app = getApp();
        var useId = app.data.useId;
        if(that.data.infor.categoryId == 1){
            wx.request({
            url: 'http://localhost:8080/cart/addCart?useId='+useId+'&proId='+that.data.proId+'&proNum=1',
            method:'POST',
            header:{
                'content-type':'application/json'
            },
            success:function(res) {
                console.log(res);
                wx.reLaunch({
                    url: '/pages/ShoppingCart/ShoppingCart',
                  })
            },
            })
        }else{
            wx.request({
                url: 'http://localhost:8080/cart/addCart?useId='+useId+'&proId='+that.data.proId+'&proNum=1&size=X',
                method:'POST',
                header:{
                    'content-type':'application/json'
                },
                success:function(res) {
                    console.log(res);
                    wx.reLaunch({
                        url: '/pages/ShoppingCart/ShoppingCart',
                      })
                },
                })
        }
        
    },
    jumpBuy(){
        var that = this;
        wx.navigateTo({
          url: '/pages/buy/buy?categoryId='+that.data.infor.categoryId+'&proId='+that.data.infor.proId,
        })
    },
    onShow(){
        this.queryPicture();
    },
    onLoad:function(option) {
        this.proId = option.proId;
        var Id = option.proId;
        this.setData({
            proId:Id
        })
    }
})